package com.cungmua.app.task;

import android.content.Context;

import com.cungmua.app.handler.BaseAuthenticatedRequestHandler;
import com.cungmua.app.handler.PaymentInfoHandler;
import com.cungmua.app.model.request.PaymentInfoRequest;
import com.cungmua.app.model.response.PaymentInfoResponse;
import com.cungmua.app.net.CungMuaAPI;

import retrofit.RetrofitError;

/**
 * Created by kelvin.nguyen on 6/25/14.
 */
public class PaymentInfoTask extends AuthenticatedTask<PaymentInfoRequest, Void, PaymentInfoResponse> {
    private final Context context;
    private final PaymentInfoHandler handler;

    public PaymentInfoTask(Context context, PaymentInfoHandler handler) {
        this.context = context;
        this.handler = handler;
    }

    @Override
    protected Context getContext() {
        return context;
    }

    @Override
    protected PaymentInfoResponse doInBackground() throws RetrofitError {
        PaymentInfoRequest request = params[0];
        return CungMuaAPI.getService().getPaymentInfo(request.toFieldMap());
    }

    @Override
    protected BaseAuthenticatedRequestHandler getHandler() {
        return handler;
    }

    @Override
    protected void onSuccess(PaymentInfoResponse paymentInfoResponse) {
        handler.onPaymentInfo(paymentInfoResponse);
    }
}

